<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <link rel="shortcut icon"  href="../static/favicon.ico" >
    <title>看板</title>
    <link rel="stylesheet" href="../static/bootstrap.min.js">
    <script type="text/javascript">
        document.write("<link rel=\"stylesheet\" href=\"../../static/style2.css\">");
    </script>

</head>
<style>
    body {
        margin: 0;
        padding: 0;
    }

    #bodyPage {
        width: 100%;
        min-height: 100%;
        height: auto !important;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
    }

    #bodyPage .bg {
        position: absolute;
        top: 0px;
        left: 0px;
        z-index: 1;
        display: none;
    }
    #div-btn1{
        z-index: 1000;
        position: absolute;
        right: 1%;
        top: 5%;
    }
    #div-btn2{
        z-index: 1000;
        position: absolute;
        right: 1%;
        top: 10%;
    }
</style>

<body>
<div id="cover" class="cover"></div>
<div class="row">
    <div class="tariffCards">


        <a class="WeeklyReport1" id="addcmp">
            <img alt="WeeklyReport" src="../static/add.jpeg"/>
            <span>添加电脑</span>
        </a>

    </div>

</div>
<div class="col-lg-4 col-md-4" id="logo_con">
    <img id="img_logo" class="img-responsive" src="../static/logo_b.png">
</div>
<div  id="div-btn1">
   <button class="btn-primary" id="btn1">设置服务器</button>
</div>
<div  id="div-btn2">
   <button class="btn-primary" id="btn2">设置管理员</button>
</div>
<script type="text/javascript" src="../static/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../static/bootstrap.min.js"></script>
<script type="text/javascript">
    userip =''
    function get_userip() {
        //獲取訪問者ip
         $.ajaxSettings.async = false;
        $.get('/get_userip', {'method': 'GET', 'text': 'test-html'}, function (data) {
            userip = data
        })
         $.ajaxSettings.async = true;
    }
    $('#btn1').click(function () {
        get_userip()
        window.location.href='http://'+userip+':7000/login'
    })
    $('#btn2').click(function () {
        get_userip()
        window.location.href='http://'+userip+':7000/set_admin'
    })
    $.post('/getcomputer',function (data) {
        cmps=JSON.parse(data);
        for(var i=0;i<cmps.length;i++){
            $(".tariffCards").prepend('<a class="WeeklyReport" >\n' +
            '            <img alt="WeeklyReport" src="../static/computer.jpeg"/>\n' +
            '            <span id="myspan"></span>\n' +
            '        </a>')
            $("#myspan").html(cmps[i])
        }

    })
    {#为动态生成的元素添加点击事件#}
    $('.tariffCards').on('click','.WeeklyReport',function () {
        myurl = 'http://'+$(this).children('#myspan').html()+':7000'
        window.open(myurl)
    })
    $('#addcmp').click(function () {
        ip = prompt('请输入电脑IP')
        if (ip != null) {
            $(".tariffCards").prepend('<a class="WeeklyReport" >\n' +
                '            <img alt="WeeklyReport" src="../static/computer.jpeg"/>\n' +
                '            <span id="myspan"></span>\n' +
                '        </a>')
            $("#myspan").html(ip)
            ipdic = {'ip': ip}
            $.post('/addcomputer', ipdic, function (data) {
                alert(data)
            })
        }

    })
    //监听右键点击
    $('.tariffCards').on('mousedown','.WeeklyReport',function (e) {
        if(3 == e.which){
             r = confirm('是否删除该电脑！！')
            if(r == true){
                ip = $(this).children('#myspan').html()
                $(this).remove()
                ipdic={'ip':ip}
                $.post('/delete',ipdic,function (data) {
                    alert(data)
                })
            }else {

            }
        }
        return false
    })
</script>
</body>
</html>
